package cn.lzx.user.controller;

import cn.lzx.basic.util.AjaxResult;
import cn.lzx.user.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * 处理发送验证码的请求
 */
@RestController
public class VerifycodeController {

    /**
     * 注入userservice
     */
    @Autowired
    private IUserService userService;

    /**
     * post请求 map中装的是 phone：页面的电话号码
     * @param map
     * @return
     */
    @PostMapping("/verifycode/smsCode")
    private AjaxResult sendSmsCode(@RequestBody Map<String,String>map ){
        try {
            //通过key值获取电话
            String phone = map.get("phone");
            //调用service层 发短信的方法 将phone传入
            userService.sendSms(phone);
            return new AjaxResult();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMsg("系统异常:"+e.getMessage());
        }
    }
}
